﻿using System;
using System.Windows.Forms;

namespace MobileCommissionManagement.VodafoneControls
{
    public partial class VodafoneDealerFilter : Form
    {
        private VodafoneController _controller;
        private string _businessType;
        private string _businessLine;
        private DateTime _yearMonth;

        #region Properties

        public VodafoneController VodafoneController
        {
            set
            {
                _controller = value;
                businessTypeLookUpEdit.Properties.DataSource = value.BusinessTypes;
            }
        }

        public string BusinessType
        {
            get { return _businessType; }
        }

        public string BusinessLine
        {
            get { return _businessLine; }
        }

        public DateTime YearMonth
        {
            get { return _yearMonth; }
        }

        #endregion


        public VodafoneDealerFilter()
        {
            InitializeComponent();
            oKSimpleButton.Click += oKSimpleButton_Click;
            businessTypeLookUpEdit.EditValueChanging += businessTypeLookUpEdit_EditValueChanging;
        }

        private bool CanFilter()
        {
            string errorMessage = string.Empty;
            if (businessTypeLookUpEdit.EditValue == null)
                errorMessage = "Por favor, indique o tipo de negócio.";
            if (businessLineLookUpEdit.EditValue == null)
                errorMessage = "Por favor, indique a linha de negócio.";
            if (yearMonthDateEdit.EditValue == null)
                errorMessage = "Por favor, indique a data.";
            if (errorMessage != string.Empty)
                MessageBox.Show(errorMessage, "Filtrar Dealer Vodafone", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return errorMessage == string.Empty;
        }

        void businessTypeLookUpEdit_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
        {
            businessLineLookUpEdit.Properties.DataSource = _controller.GetBusinessLines(e.NewValue.ToString());            
        }

        void oKSimpleButton_Click(object sender, EventArgs e)
        {
            if (!CanFilter())
            {
                DialogResult = DialogResult.None;
                return;
            }
            _businessType = (string)businessTypeLookUpEdit.EditValue;
            _businessLine = (string)businessLineLookUpEdit.EditValue;
            _yearMonth = (DateTime)yearMonthDateEdit.EditValue;
        }
    }
}
